package LeetCode;
//给定一个链表，删除链表的倒数第 n 个结点，并且返回链表的头结点
public class Offer_21 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummyHead = new ListNode(101);
        dummyHead.next = head;
        ListNode fast = head;
        ListNode slow = dummyHead;
        for (int i = 0; i < n; i++) {
            fast = fast.next;
        }
        while (fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        ListNode cur = slow.next;
        slow.next = cur.next;
        return dummyHead.next;
    }
}
